<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>倒计时</title>
    <style>
        #box button{
            font-size:60px;
            width:300px;
            text-align:center;
        }
    </style>
</head>
<body>

<button onclick="timer = setInterval('timeTozone()',1000);"><h3>开始</h3></button>
<div id="time" style="font-size:200px;color:#666;">00:00</div>

<hr>
<h1 id="box"></h1>

<script>

    var maxt = 65;
    function timeTozone(){
        if(maxt>=0){
            var hour = Math.floor(maxt/60/60);
            var min = Math.floor(maxt/60);
            var sec = Math.floor(maxt%60);
            if (maxt>60*60) {
                min=Math.floor(maxt%(60*60)/60);
            }
            hour=(hour>9)?hour:'0'+hour;
            min=(min>9)?min:'0'+min;
            sec=(sec>9)?sec:'0'+sec;
            var msg = hour+':'+min+":"+sec;
            document.getElementById("time").innerHTML = msg;
            --maxt;
        }else{
            clearInterval(timer);
            document.getElementById("time").innerHTML = '0:0:0<br>时间到!';
            return;
        }
    }



    //声明 要倒计时 的秒数
    var seconds = 65;
    run();//调用run
    //定时函数
    var timer2 = setInterval(run, 1000);

    //定义函数
    function run(){
        //判断 倒计时结束
        if (seconds <= 0) {
            document.getElementById('box').innerHTML = "<button>抢购</button>";
            clearInterval(timer2);
            return;
        }
        //取出 时间中 的小时数
        var h = Math.floor(seconds / 3600);
        //获取分钟数
        var s = seconds - h * 3600;
        var i = Math.floor(s / 60);
        //获取秒数
        s -= i * 60;
        
        //处理 时分秒 的格式
        h = (h > 9)?h:'0'+h;
        i = (i > 9)?i:'0'+i;
        s = (s > 9)?s:'0'+s;
        
        //把时分秒 输出 到指定位置
        var timeStr = "距离本次团购还有 "+h+'时'+i+'分'+s+'秒';
        document.getElementById('box').innerHTML = timeStr;
        //秒数 -1
        seconds --;
    }
    
</script>
</body>
</html>